// app.js
App({
  onLaunch() {
    let that = this
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.log(">>>>>> wx.login() ", res )
      }
    })

    // 获取用户信息
    wx.getSetting({
      withSubscriptions:true,
      success(res){
        console.log(">>>>>> wx.getSetting() ", res)

        //已授权，可以直接调用 wx.getUserInfo() 获取头像昵称，不会弹框
        if(res.authSetting['scope.userInfo']){
          wx.getUserInfo({
            success: res => {
              console.log(">>>>>> wx.getUserInfo() ", res)
              that.globalData.userInfo = res.userInfo
            }
          })
        }

      },
    })
  },
  globalData: {
    userInfo: null,
  }
})
